package com.burgeon.backend.SHOPBACKEND.controller;


import com.burgeon.backend.SHOPBACKEND.entity.recored.MessageRecore;
import com.burgeon.backend.SHOPBACKEND.service.RecordService;
import com.burgeon.backend.stsutil.ResponseResult;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;

@RequestMapping("record")
@RestController
@CrossOrigin
public class RecordController extends BaseController {

    @Autowired
    private RecordService recordService;

    /**
     * 获取消息纪录
     * @param daoId
     * @param openId
     * @return
     */
    @RequestMapping("getRecord")
    public ResponseResult<List<MessageRecore>> getRecord(String daoId, String openId,int page,String ip) throws JSONException {

        List<MessageRecore> data = recordService.getAppRecord(daoId,openId,page,ip);

        return new ResponseResult<>(SUCCESS,data);
    }

    //1.將JSONObject转换为HashMap<String,String>
    public static HashMap<String, String> JsonObjectToHashMap(JSONObject jsonObj) throws JSONException {
        HashMap<String, String> data = new HashMap<String, String>();
        Iterator it = jsonObj.keys();
        while(it.hasNext()){
            String key = String.valueOf(it.next().toString());
            String value = (String)jsonObj.get(key).toString();
            data.put(key, value);
        }
        System.out.println(data);
        return data;
    }

}
